001 /* $RCSfile: DESede3KeySecretKeyFactoryEngine.java,v $ 002 * $Revision: 1.10 $ 003 * $Date: 2003/10/04 19:18:38 $ 004 * $Author: uwe_guenther $ 005 * $State: Exp $ 006 * 007 * Created on August 13, 2001 9:45 PM 008 * 009 * Copyright (C) 2001 Uwe Guenther <uwe@cscc.de> 010 * 011 * This file is part of the jhbci JCE-ServiceProvider. The jhbci JCE- 012 * ServiceProvider is a library, written in JavaTM, that should be 013 * used in HBCI banking applications (clients and may be servers), 014 * to do cryptographic operations. 015 * 016 * The jhbci library is free software; you can redistribute it and/or 017 * modify it under the terms of the GNU Lesser General Public 018 * License as published by the Free Software Foundation; either 019 * version 2.1 of the License, or (at your option) any later version. 020 * 021 * The jhbci library is distributed in the hope that it will be useful, 022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 024 * Lesser General Public License for more details. 025 * 026 * You should have received a copy of the GNU Lesser General Public 027 * License along with this library; if not, write to the Free Software 028 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 029 * 030 */ 031 032 package de.cscc.crypto.provider; 033 034 import java.security.InvalidKeyException; 035 import java.security.spec.InvalidKeySpecException; 036 import java.security.spec.KeySpec; 037 038 import javax.crypto.SecretKey; 039 import javax.crypto.SecretKeyFactorySpi; 040 041 /** 042 * DESede3KeySecretKeyFactoryEngine Class. 043 * 044 * @author <a href=mailto:uwe@cscc.de>Uwe Günther</a> 045 * @version $Revision: 1.10 $ 046 */ 047 public final class DESede3KeySecretKeyFactoryEngine extends SecretKeyFactorySpi { 048 049 /** The delegate for this wrapper object */ 050 private DESede3KeySecretKeyFactoryImpl factory = 051 new DESede3KeySecretKeyFactoryImpl(); 052 053 /** 054 * Creates new DESede3KeySecretKeyFactoryEngine. 055 * 056 * @throws SecurityException if the provider self integrity check fails. 057 */ 058 public DESede3KeySecretKeyFactoryEngine() { 059 if (JHBCI.selfIntegrityChecking() == false) { 060 throw new SecurityException("JHBCI-Provider is tampered."); 061 } 062 } 063 064 /** 065 * Returns a string representation of the object. 066 * 067 * @return a string representation of the object. 068 */ 069 public String toString() { 070 return this.factory.toString(); 071 } 072 073 /** 074 * Generates a <code>SecretKey</code> object from the 075 * provided key specification (key material). 076 * 077 * @param keySpec the specification (key material) of the secret key. 078 * @return the secret key. 079 * @exception InvalidKeySpecException if the given key specification 080 * is inappropriate for this secret-key factory to produce a secret key. 081 */ 082 protected SecretKey engineGenerateSecret(KeySpec keySpec) 083 throws InvalidKeySpecException { 084 return this.factory.generateSecret(keySpec); 085 } 086 087 /** 088 * Returns a specification (key material) of the given key object in the 089 * requested format. 090 * 091 * @param key the key. 092 * @param keySpec the requested format in which the key material shall be 093 * returned. 094 * @return the underlying key specification (key material) in the requested 095 * format. 096 * @throws NullPointerException if key or keySpec is null. 097 * @throws InvalidKeySpecException if the requested key specification is 098 * inappropriate for the given key (e.g., the algorithms associated with 099 * <code>key</code> and <code>keySpec</code> do not match, or 100 * <code>key</code> references a key on a cryptographic hardware device 101 * whereas <code>keySpec</code> is the specification of a software-based 102 * key), or the given key cannot be dealt with (e.g., the given key has 103 * an algorithm or format not supported by this secret-key factory). 104 */ 105 protected KeySpec engineGetKeySpec(SecretKey key, Class keySpec) 106 throws InvalidKeySpecException { 107 return this.factory.getKeySpec(key, keySpec); 108 } 109 110 /** 111 * Translates a key object, whose provider may be unknown or potentially 112 * untrusted, into a corresponding key object of this secret-key factory. 113 * 114 * @return they key whose provider is unknown or untrusted. 115 * @param key the key whose provider is unknown or untrusted. 116 * @throws NullPointerException if key is null. 117 * @throws InvalidKeyException if the given key cannot be processed by this 118 * secret-key factory. 119 */ 120 protected SecretKey engineTranslateKey(SecretKey key) 121 throws InvalidKeyException { 122 return this.factory.translateKey(key); 123 } 124 }